#!/usr/bin/env python
#-*- coding: UTF-8 -*-
__author__ = '愚夫'
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import argparse,os,sys,logging
def serve(host,port,username,password,path):
    logging.basicConfig(filename='/var/log/pyftpd.log', level=logging.INFO)
    auth = DummyAuthorizer()
    auth.add_user(username,password,path,'elradfmwM')
    handler = FTPHandler
    handler.authorizer = auth
    handler.banner = 'welcome'
    server = FTPServer((host,port),handler)
    server.serve_forever()
    pass

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('host')
    parser.add_argument('port')
    parser.add_argument('username')
    parser.add_argument('password')
    parser.add_argument('path')
    arg = parser.parse_args()
    host,port,username,password,path = arg.host,arg.port,arg.username,arg.password,arg.path
    if not os.path.isdir(path):
        sys.exit(u'非法路径')
    serve(host,port,username,password,path)
